import java.util.Queue;

public class MyQueue {
    //队列用单向链表存储
    private class Node {
        private int data;
        private Node next;

        public Node(int data) {
            this.data = data;
        }
    }

    private Node head;//记录头节点
    private Node last;//记录尾节点

    //入队
    public boolean offer(int data) {
        Node node = new Node(data);
        if (this.head == null) {
            this.head = node;
            this.last = node;
        } else {
            this.last.next = node;
            this.last = node;
        }
        return true;
    }

    //出队
    public int poll() {
        if (this.head == null) {
            return -1;
        } else {
            int ret = this.head.data;
            this.head = head.next;
            return ret;
        }
    }

    //获取队头元素
    public int peek() {
        if (this.head == null) {
            return -1;
        } else {
            return this.head.data;
        }
    }

    //获取队列中的有效个数
    public int size() {
        if (this.head == null) {
            return 0;
        }
        int count = 0;
        Node src = this.head;
        while (src != this.last.next) {
            count++;
            src = src.next;
        }
        return count;
    }

    //判断队列是否为空
    public boolean isEmpty() {
        if (this.head == null) {
            return true;
        }
        return false;
    }
}
class Test {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.offer(1);

        System.out.println(myQueue.size());
        System.out.println(myQueue.poll());
        System.out.println(myQueue.poll());
        System.out.println(myQueue.size());
        System.out.println(myQueue.peek());
        System.out.println(myQueue.size());
        System.out.println(myQueue.isEmpty());
    }
}